package org.flashbrighton.as3bots.display
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	
	public class HitPoint extends Sprite
	{
		
		private var _amount:Number;
		private var _tf:TextField;
		private var _timer:Timer;
		
		public function HitPoint(amount:Number)
		{
			_amount = amount;
			addEventListener(Event.ADDED_TO_STAGE, create);
		}
		
		
		private function create(e:Event):void
		{
			var colour:uint;
			colour = (_amount < 0) ? 0xFF0000 : 0x00FF00;
			
			_tf = new TextField();
			_tf.defaultTextFormat = new TextFormat("Arial", 14, colour);
			_tf.text = String(_amount);
			addChild(_tf);
			
			_timer = new Timer(1000);
			_timer.addEventListener(TimerEvent.TIMER, destroy);
			_timer.start();
		}
		
		
		private function destroy(e:Event):void
		{
			removeChild(_tf);
			_timer.removeEventListener(TimerEvent.TIMER, destroy);
		}
		

	}
}